package com.ciaojian.bytedance.service;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.ciaojian.core.bytedance.api.ByteDanceRequestApi;
import com.ciaojian.bytedance.enums.BalanceChannelTypeEnums;
import com.ciaojian.core.bytedance.MiniAppRequestApi;
import com.ciaojian.bytedance.util.Sign;
import com.ciaojian.core.bytedance.ByteDanceMiniConfig;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class FinanceService {


    public JSONObject query_merchant_balance(Integer channelType) {
        log.info("###商户余额接口##");
        JSONObject param = new JSONObject();
        param.put("app_id", ByteDanceMiniConfig.APP_ID);
//        param.put("thirdparty_id", ByteDanceMiniConfig.APP_ID);
        param.put("merchant_uid", ByteDanceMiniConfig.MERCHANT_UID);
        if (channelType==1) {
            param.put("channel_type", BalanceChannelTypeEnums.alipay.getChannel());
        }else if (channelType==2){
            param.put("channel_type", BalanceChannelTypeEnums.wx.getChannel());
        }else if (channelType==3){
            param.put("channel_type", BalanceChannelTypeEnums.dy.getChannel());
        }else if (channelType==4){
            param.put("channel_type", BalanceChannelTypeEnums.yzt.getChannel());
        }
        String sign = Sign.requestSign(param);
        param.put("sign", sign);
        JSONObject result = new JSONObject();
        try{

            String poi_sync_store = ByteDanceRequestApi.sendRequest(MiniAppRequestApi.QUERY_MERCHANT_BALANCE, param);

            result = JSON.parseObject(poi_sync_store);

            return result;

        }catch (Exception e){
            return result;
        }
    }



}
